<template>
	<view class="page-index">
		<view class="List" v-if="List!=''">
			<view class="header">
				<image :src="List.avatar" mode="" style="width: 60rpx;height: 60rpx;border-radius: 50%;"></image>
				<view class="box">
					<view class="name">
						{{List.nickname}}
					</view>
					<view class="time">
						{{List.time}}
					</view>
				</view>
			</view>
			<view class="title">
				<view class="title-item1">
					{{List.title}}
				</view>
			</view>
			<!-- 			<view class="address">
				{{item.address}}
			</view> -->
			<view class="remarks">
				{{List.text?List.text:''}}
			</view>
			<view class="image-box" v-if="List.images">
				<image :src="item" mode="" v-for="(item,index) in List.images" :key="index" class="image" @click="imageSee(item,index)"></image>
			</view>
			<!-- 			<view class="space">
			</view> -->
		</view>
		<view class="fixed">
			<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" class="nbtn" v-if="!token">
				<view style="text-align: center;color: #ffffff;">
					拨打电话
				</view>
			</button>
			<view class="Submit" @click="call()" v-else>
				拨打电话
			</view>
		</view>
	</view>
</template>

<script>
	import * as index from '@/api/index.js'
	import * as user from '@/api/user.js'
	export default {
		data() {
			return {
				page: 1,
				List: {
					avatar: '',
					id: '',
					title: '',
					text: '',
					images: [],
					time: '',
					nickname: '',
					member_id: '',
					type: '',
					heng: ''
				}, //列表
				loginInfo: {
					code: '',
					phoneCode: ''
				}, //登录信息
				token: ''
			}
		},
		onLoad(params) {
			this.token = uni.getStorageSync('token')
			this.getList(params.id)
		},
		onReachBottom() {

		},
		methods: {
			getList(id) {
				index.getWantInfo({ wantId: id }).then(res => {
					console.log(res.data);
					this.List = res.data
				})
			},
			imageSee(item, index) {
				uni.previewImage({
					urls: this.List.images,
					current: index,
					longPressActions: {
						itemList: ['发送给朋友', '保存图片', '收藏'],
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			},
			call() {
				index.getWantPhone({ wantId: this.List.id }).then(res => {
					uni.makePhoneCall({
						phoneNumber: res.data.phone //仅为示例
					});
				})
			},
			getPhoneNumber(e) {
				let that = this
				that.loginInfo.phoneCode = e.detail.code
				if (that.loginInfo.phoneCode) {
					uni.login({
						provider: 'weixin',
						onlyAuthorize: true,
						success: function(loginRes) {
							that.loginInfo.code = loginRes.code
							that.wxLogin()
						}
					});
				}
			},
			wxLogin() {
				let that = this
				user.wxLogin(this.loginInfo).then(res => {
					console.log(res);
					uni.setStorage({
						key: 'token',
						data: res.data.token,
						success: function() {
							that.token = res.data.token
						}
					});
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.page-index {
		font-family: PingFang SC-Medium, PingFang SC;

		.List {
			padding: 42rpx;
			background: #FFFFFF;

			.header {
				display: flex;
				justify-content: flex-start;
				margin-bottom: 18rpx;
				align-items: center;

				.box {
					margin-left: 16rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					padding: 8rpx;

					.name {
						font-size: 28rpx;
						font-weight: 700;
						color: #333333;
						line-height: 38rpx;
					}

					.time {
						font-size: 24rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #333333;
						line-height: 28rpx;
						opacity: 0.6;
					}
				}
			}

			.title {
				font-size: 32rpx;
				font-weight: 700;
				color: #333333;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
				display: flex;
				justify-content: space-between;

				.title-item1 {
					width: 540rpx;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}


			}

			.address {
				padding: 8rpx 0;
				font-size: 26rpx;
				font-weight: 400;
				color: #9E9E9E;
			}

			.remarks {
				padding: 16rpx 0;
				font-size: 24rpx;
				font-weight: 400;
				color: #202020;
			}

			.image-box {
				// padding: 24rpx 0;
				// border-top: 2rpx solid #EAEAEA;

				.image {
					width: 200rpx;
					height: 155rpx;
					border-radius: 24rpx;
					margin-left: 20rpx;
				}

				.image:nth-child(1) {
					margin-left: 0;
				}
			}


			.space {
				height: 20rpx;
				background: #f8f8f8;
				margin: 0rpx -42rpx;
				margin-top: 40rpx;
			}
		}

		.fixed {
			padding: 0 32rpx;
			background: #FFFFFF;
			position: fixed;
			bottom: 0;
			padding-bottom: env(safe-area-inset-bottom);
			width: 100%;
			height: 160rpx;
			margin: 0 -30rpx;

			// padding: 40rpx;
			.Submit {
				// width: 100%;
				// height: 100%;
				height: 80rpx;
				line-height: 80rpx;
				margin: 40rpx;
				background: #006FD0;
				text-align: center;
				border-radius: 16rpx;
				color: #FFFFFF;
			}

			.nbtn {
				height: 80rpx;
				line-height: 80rpx;
				margin: 40rpx;
				border-radius: 16rpx;
				text-align: center;
				-webkit-tap-highlight-color: transparent;
				box-sizing: content-box;
				cursor: pointer;
				position: relative;
				text-align: left;
				text-decoration: none;
				background: #ffffff;
				background: #006FD0;
				padding: 0;
				font-size: 28rpx;
			}

			.nbtn::after {
				border: 0px solid rgba(0, 0, 0, 0);
				border-radius: 0px;
			}
		}
	}
</style>
